package org.openkoala.koala.wizard.wizardpage.dialog;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.openkoala.koala.wizard.wizardpage.ModuleConfigWizardPage;
/**
 * 监控的详细配置
 * @author lingen
 *
 */
public class MonitorConfigDialog extends Dialog {
	
	private Button monitorDistributed;
	
	private Button monitorIntegrated;
	
	public final static String Distributed = "Distributed";
	
	public final static String Integrated = "Integrated";
	
	private String type = "all";
	
	private ModuleConfigWizardPage moduleConfig;

	public MonitorConfigDialog(Shell parentShell,ModuleConfigWizardPage moduleConfig,String type) {
		super(parentShell);
		this.moduleConfig = moduleConfig;
		this.type = type;
	}

	@Override
	protected Control createDialogArea(Composite composite) {
		GridData modulesGridData = new GridData(GridData.FILL_HORIZONTAL);
		modulesGridData.grabExcessHorizontalSpace = true;

		//控件
		Group monitorType = null;
		monitorType = new Group(composite, SWT.NULL);
		monitorType.setText("choose monitor type:");
		monitorType.setLayout(new GridLayout(4, false));
		monitorType.setLayoutData(modulesGridData);
		
		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
		gridData.grabExcessHorizontalSpace = true;
		
		monitorDistributed = new Button(monitorType, SWT.RADIO);
		monitorDistributed.setLayoutData(gridData);
		monitorDistributed.setText(Distributed);
		if(type.equals("client"))monitorDistributed.setSelection(true);
		
		monitorIntegrated = new Button(monitorType, SWT.RADIO);
		monitorIntegrated.setLayoutData(gridData);
		monitorIntegrated.setText(Integrated);
		if(type.equals("all"))monitorIntegrated.setSelection(true);
		
		return super.createDialogArea(composite);
	}

	public String getMonitorType(){
		if(monitorIntegrated.getSelection()){
			return "all";
		}
		else if(monitorDistributed.getSelection()){
			return "client";
		}
		return null;
	}
	
	@Override
	protected void okPressed() {
		if(getMonitorType().equals(type)==false){
			type = getMonitorType();
			moduleConfig.refreshMonitorConfig(type);
		}
		super.okPressed();
	}
	

}
